package net.fdukedom.epicurus.presentation.actions.pub;

import net.fdukedom.epicurus.presentation.actions.AbstractAction;
import net.fdukedom.epicurus.resource.ResourceDispatcher;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Dispatches requests to plugins.
 *
 * @author Dmitry Y. Kochelaev
 */
public class RequestDispatcherAction extends AbstractAction {

    private ResourceDispatcher resourceDispatcher = ResourceDispatcher.getInstance();

    protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        ActionForward forward = resourceDispatcher.findPageByName(request.getParameter("page"));
        if (forward == null) {
            forward = mapping.findForward("default");
        }
        return forward;
    }
}
